from usr.WLAN import ESP8266
from machine import UART
import usocket
import utime

def get_wifistatus():
    udp = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)
    udp.bind(('172.16.1.2', 6000))
    udp.settimeout(10)
    utime.sleep(1)
    udp.sendto(b'F100010', ('172.16.1.2', 1000))
    utime.sleep(1)
    data = udp.recv(7)
    print(data)
    udp.close()

def open_wifi():
    id = 'CU_5f2X'
    pwd = 'xsvuz5xw'
    wifi = ESP8266()
    ret = wifi.station(id, pwd)
    print(ret)
    wifi.set_dns('114.114.114.114','8.8.8.8')
    print(wifi.ipconfig())
    wifi.set_default_NIC('172.16.1.2')
    utime.sleep(1)
    print("version:")
    print(wifi.version())
    utime.sleep(1)
    status = wifi.status()
    print("wifi status:{0:d}".format(status))
    wifi.stop()